{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "71c965ef-e6d4-4e44-8ed3-bb4096dca86e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "19a24b94-d714-4155-9b9c-964f4db47747",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = np.array([1,2,3,4,5], dtype=np.float32)\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3f7e477e-7649-4ca5-bdb4-43c98a94810e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('float32')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2281616b-b34e-48e8-97d8-4b892d55bedf",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array.nbytes #占多少个bit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "556017c2-0491-4b2a-90dd-b3c91842c6a4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['1', '10', '3.5', 'str'], dtype='<U32')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = np.array([1,10,3.5,\"str\"]) #当array中有不同类型\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "73e5ae33-2f03-430d-9fbd-fac8a0396de0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = np.array([1,2,3,4,5])\n",
    "np.asarray(fang_array, dtype = np.float32) #重新指定类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7c92577a-cc4b-437e-9f60-667229c2791e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array #np.asarray不会改变数据本身"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "05909f7b-42fb-4ecb-8498-ca2deec82ae0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array.astype(np.float32) #astype也不会改变数据本身"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0040aab-8749-4565-86cf-adb7a6644904",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
